import moment from 'moment';

export const getFormOption = {
  menuPosition: 'right',
  submitBtn: false,
  emptyBtn: false,
  column: [
    {
      label: '时间范围',
      span: 6,
      prop: 'examineDate',
      type: 'monthrange',
      format: 'yyyy-MM',
      valueFormat: 'yyyy-MM',
      startPlaceholder: '开始日期',
      endPlaceholder: '结束日期',
      rules: [
        {
          required: true,
          message: '请选择时间范围',
          trigger: 'blur'
        },
        {
          trigger: 'change',
          validator: (rule, value, callback) => {
            const endTime = value[1];
            const startTime = value[0];
            if (moment(endTime).diff(moment(startTime), 'day') > 365) {
              callback(new Error('查询时间最多选择一年'));
            }
            callback();
          }
        }
      ]
    },
    {
      label: '产线',
      prop: 'lineId',
      span: 6,
      type: 'select',
      dicUrl: '/api/mes-product/productionline/list',
      props: {
        label: 'name',
        value: 'id'
      },
      filterable: true
    },
    {
      label: '',
      prop: 'btn',
      span: 6,
      formslot: true
    }
  ]
};

export const tableOption = {
  border: true,
  addBtn: false,
  viewBtn: false,
  editBtn: false,
  delBtn: false,
  index: true,
  menu: true,
  columnBtn: false,
  refreshBtn: false,
  menuWidth: 120,
  viewBtnText: '详情',
  indexLabel: '序号',
  width: 100,
  column: [
    {
      label: '日期',
      prop: 'date'
    },
    {
      label: '产线',
      prop: 'lineName'
    },
    {
      label: '总检批次数',
      prop: 'examineTotalTimes'
    },
    {
      label: '合格批次数',
      prop: 'examineOkTimes',
      span: 7
    },
    {
      label: '不合格批次数',
      prop: 'examineNgTimes',
      span: 7
    },
    {
      label: '目标值',
      prop: 'targetValue'
    },
    {
      label: '批合格率',
      prop: 'passRate',
      formatter: (val) => {
        return val.passRate ? val.passRate + '%' : '';
      }
    },
    {
      label: '达成情况',
      prop: 'achievementStatus',
      html: true,
      formatter: (val) => {
        if (val.achievementStatus === 'OK') {
          return '<span class="text-green">' + 'OK' + '</span>';
        } else if (val.achievementStatus === 'NG') {
          return '<span class="text-red">' + 'NG' + '</span>';
        } else {
          return '';
        }
      }
    }
  ]
};

export const chartOption = {
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'cross',
      crossStyle: {
        color: '#999'
      }
    }
  },
  toolbox: {},
  legend: {
    data: ['目标值', '合格率'],
    textStyle: {
      lineHeight: 60 // 设置行高为 30 来平移图例
    }
  },
  title: {
    text: 'OQC批合格率统计图',
    left: 'center'
  },
  xAxis: {},
  yAxis: {
    start: 0,
    type: 'value',
    min: 0,
    max: 100,
    interval: 20,
    axisLabel: {
      formatter: '{value}%'
    },
    nameTextStyle: {
      // fontWeight: 'bold',
      // fontSize: 16
      // padding: [0, 60, 20, 0]
    },
    name: ''
    // nameLocation: 'start'
  },
  series: [
    {
      name: '目标值',
      type: 'line',
      color: ['#f6d054'],
      data: []
    },
    {
      name: '合格率',
      type: 'bar',
      color: ['#75BD42'],
      data: []
    }
  ]
};
